/*
 * @Author: zcwhy 12345678
 * @Date: 2023-10-31 15:28:33
 * @LastEditors: zcwhy 12345678
 * @LastEditTime: 2024-02-04 16:40:48
 * @FilePath: \xxProject\src\router\index.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
import knapsack from '../views/knapsack.vue'
import map from '../views/map.vue'
import activity from '../views/activity.vue'
import { getToken } from '@/utils/auth';
import accomplishment from '../views/accomplishment.vue'
import place from '../views/place.vue'
import ranking from '../views/ranking.vue'

import friend from '../views/friend.vue'
import useUserStore from '@/store/modules/user'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      component: HomeView
    },
    {
      path: '/map',
      name: 'map',
      component: map
    },
    {
      path: '/activity',
      name: 'activity',
      component: activity
    },
    {
      path: '/knapsack',
      name: 'knapsack',
      component: knapsack
    },
    {
      path: '/accomplishment',
      name: 'accomplishment',
      component: accomplishment
    },
    {
      path: '/ranking',
      name: 'ranking',
      component: ranking
    },
    {
      path: '/place',
      name: 'place',
      component: place
    },

    {
      path: '/friend',
      name: 'friend',
      component: friend
    },
  ]
})
router.beforeEach((to, from, next) => {
  if (!useUserStore().name) {
    // 判断当前用户是否已拉取完user_info信息
    useUserStore()
      .getInfo()
      .then(() => {
        next();
      })
  } else {
    next();
  }
});

export default router
